<?php


namespace app\controller;


use think\facade\Config;
use think\facade\Request;
use think\Response;

/**
 * Class Base
 * @package app\controller
 */
abstract class Base
{

    /**
     * @var int
     */
    protected $page;
    /**
     * @var int
     */
    protected $pageSize;

    //构造一个供子类直接使用的方法

    /**
     * Base constructor.
     */
    public function __construct()
    {
        //获取分页
        $this->page = (int)Request::param('page');

        //获取条数,参数写在app.php中
        $this->pageSize = (int)Request::param('page_size',Config::get('app.page_size'));
    }

    /**
     * @param $data
     * @param string $msg
     * @param int $code
     * @param string $type
     * @return Response
     */
    protected function create($data, string $msg = '' , int $code = 200, string $type='json') : Response
    {
        $result = [
            'code'=>$code,
            'msg'=>$msg,
            'data'=>$data
        ];

        //返回api接口
        return Response::create($result,$type);
    }

    /**
     * @param $name
     * @param $arguments
     * @return Response
     */
    public function __call($name, $arguments)
    {
        //方法不存在时错误提示，404
        return $this->create([],'资源不存在',404);
    }
}